const BASE_URL_TEST = 'http://192.168.20.213:8989'

//使用GET获取角色分页列表
export const getRolesPage = async () => {
  try {
    const res = await fetch(BASE_URL_TEST + '/roles/page?pageNum=1&pageSize=10')
    return res.json(); //返回json数据
  } catch (error) {
    console.log(error + 'error');
  }
};


//使用POST增加角色
export const postRoles = async () => {
  const myHeaders = new Headers();
  myHeaders.append("Content-Type", 'application/json');
  myHeaders.append('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySW5mbyI6eyJ1c2VySWQiOjIsInVzZXJuYW1lIjoiYWRtaW4iLCJuaWNrbmFtZSI6Iuezu-e7n-euoeeQhuWRmGFkbWluIiwiZGVwdElkIjoxLCJyb2xlcyI6IkFETUlOIn0sImlzcyI6ImR5czYyMzAiLCJleHAiOjE3MzIwMTU0ODMsIm5iZiI6MTczMTk3OTQ4MywiaWF0IjoxNzMxOTc5NDgzfQ.6aglo9EBRoknFCP1JRIcvtRcBdC1TihxxmOrlUwtiCA');

  const newRole = {
    id: 23515,
    name: '一路寒风身如絮',
    code: '命海沉浮客独行',
    sort: 1145,
    status: 1,
    dataScope: 1,
  };

  const requestOption = {
    method: 'POST',
    headers: myHeaders,
    body: JSON.stringify(newRole)
  };

  const res = await fetch(BASE_URL_TEST + '/roles', requestOption);

  if (res.ok) {
    return res.json();
  }
};

//使用PUT修改角色信息  id
export const putRolesByRoleID = () => {
  const myHeaders = new Headers();
  myHeaders.append('Content-Type', 'application/json'); //请求头  省略掉了token

  const raw = {
    id: 23513,
    name: '野兽先辈',
    code: '114514',
    sort: 1145,
    status: 1,
    dataScope: 1145,
  };

  const resquestOptions = {
    method: 'PUT',
    headers: myHeaders,
    body: JSON.stringify(raw),
  };

  fetch(BASE_URL_TEST + '/roles/23491', resquestOptions)
    .then((response) => response.text())
    .then((result) => console.log(result))
    .then((error) => console.log(error + 'error'));
};

//使用DELETE删除角色信息
export const deleteRolesByids = () => {
  const resquestOptions = {
    method: 'DELETE',
  };

  fetch(BASE_URL_TEST + '/roles/23491', resquestOptions)
    .then((response) => response.text())
    .then((result) => console.log(result))
    .then((error) => console.log(error + 'error'));
};

//使用patch修改角色单个字段
export const patchRolesByids = () => {
  const resquestOptions = {
    method: 'PATCH',
  };

  fetch(BASE_URL_TEST + '/roles/23491/status?status=1', resquestOptions)
    .then((response) => response.text())
    .then((result) => console.log(result))
    .then((error) => console.log(error + 'error'));
};



